package com.baofu.paycore.service.validate.impl.preAuth;

import com.baofu.paycore.service.facade.enums.PayCoreErrorCode;
import com.baofu.paycore.service.facade.model.authorize.AuthorizeDTO;
import com.baofu.paycore.service.validate.AbstractPayValidate;
import com.system.commons.exception.BizServiceException;
import com.system.commons.utils.ParamValidate;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

/**
 * 预授权校验
 * <p>
 * 1.
 * </p>
 * User: xin deng  Date: 16/8/30 ProjectName: paycore Version: 1.0
 */
@Slf4j
@Service
public class PreAuthValidate extends AbstractPayValidate<AuthorizeDTO> {

    /**
     * 参数基本校验 格式及非空校验
     * @param t     被校验对象
     */
    public void paramsValidate(AuthorizeDTO t){
        ParamValidate.validateParams(t);
        if (!t.getAmt().equals(t.getAuthorizeFundDTO().getPayToolAmount())){
            log.error("预授权主单金额:{} 资金对象金额:{}", t.getAmt(), t.getAuthorizeFundDTO().getPayToolAmount());
            throw new BizServiceException(PayCoreErrorCode.AMT_IS_NOT_IN_CONFORMITY, "预授权主单金额与资金单金额不符");
        }
    }
}
